package edu.ku.it.si.springjpaexample.dao;

import java.util.List;

import edu.ku.it.si.springjpaexample.util.WebTool;

public class PageView<T> {
	/** 分页数据 **/
	private List<T> results;
	/** 总分页数 **/
	private long totalPage = 1;
	/** 页码索引的开始和结束 **/
	private PageIndex pageIndex;
	/** 每页的记录数 **/
	private int maxResult = 10;
	/** 当前所在页  **/
	private int currentPage = 1;
	/** 总记录数 **/
	private long totalrecord;
	/** 每页显示的页码 **/
	private int pageCode = 1;
	
	public int getPageCode() {
		return pageCode;
	}

	public void setPageCode(int pageCode) {
		this.pageCode = pageCode;
	}

	public void setQueryResult(QueryResult qr){
		setTotalrecord(qr.getTotalResult());
		setResults(qr.getResultList());
	}
	
	public PageView(int maxResult, int currentPage) {
		this.maxResult = maxResult;
		this.currentPage = currentPage;
	}
	public List<T> getResults() {
		return results;
	}
	public void setResults(List<T> results) {
		this.results = results;
	}
	public PageIndex getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(PageIndex pageIndex) {
		this.pageIndex = pageIndex;
	}
	public int getMaxResult() {
		return maxResult;
	}
	public void setMaxResult(int maxResult) {
		this.maxResult = maxResult;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public long getTotalrecord() {
		return totalrecord;
	}
	public void setTotalrecord(long totalrecord) {
		this.totalrecord = totalrecord;
		setTotalPage(this.totalrecord%this.maxResult==0? this.totalrecord/this.maxResult : this.totalrecord/this.maxResult+1);
	}
	
	public long getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
		this.pageIndex = WebTool.getPageIndex(pageCode, currentPage, totalPage);
	}
}
